home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / mui32dev.lha / MUI / Developer / C / Examples / SaveLoad.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  5KB  |  201 lines

  1. /*
  2. ** The Settings Demo shows how to load and save object contents.
  3. */
  4.  
  5. #include "demo.h"
  6.  
  7. #define ID_CANCEL 1
  8. #define ID_SAVE   2
  9. #define ID_USE    3
  10.  
  11. SAVEDS ASM VOID HelpFunc(REG(a2) Object *help,REG(a1) Object **objptr)
  12. {
  13.     LONG udata = NULL;
  14.     if (*objptr) get(*objptr,MUIA_UserData,&udata);
  15.     set(help,MUIA_Text_Contents,udata);
  16. }
  17.  
  18. int main(int argc,char *argv[])
  19. {
  20.     APTR app,window,str1,str2,str3,sl1,cy1,help,btsave,btuse,btcancel;
  21.     ULONG signals;
  22.     BOOL running = TRUE;
  23.     static char *sex[] = { "male", "female", NULL };
  24.     static struct Hook HelpHook = { {0,0}, (VOID *)HelpFunc, 0, 0 };
  25.  
  26.     init();
  27.  
  28.     app = ApplicationObject,
  29.         MUIA_Application_Title      , "Settings",
  30.         MUIA_Application_Version    , "$VER: Settings 13.57 (30.01.96)",
  31.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  32.         MUIA_Application_Author     , "Stefan Stuntz",
  33.         MUIA_Application_Description, "Show saving and loading of settings",
  34.         MUIA_Application_Base       , "SETTINGS",
  35.  
  36.         SubWindow, window = WindowObject,
  37.             MUIA_Window_Title, "Save/use me and start me again!",
  38.             MUIA_Window_ID   , MAKE_ID('S','E','T','T'),
  39.             MUIA_Window_NeedsMouseObject, TRUE,
  40.  
  41.             WindowContents, VGroup,
  42.  
  43.                 Child, ColGroup(2), GroupFrameT("User Identification"),
  44.                     Child, Label2("1:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 1, End,
  45.                     Child, Label2("2:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 2, End,
  46.                     Child, Label2("3:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 3, End,
  47.                     Child, Label2("4:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 4, End,
  48.                     Child, Label2("5:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 5, End,
  49.                     Child, Label2("10:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 10, End,
  50.                     Child, Label2("100:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 100, End,
  51.                     Child, Label2("200:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 200, End,
  52.                     Child, Label2("300:"), Child, StringObject, StringFrame, MUIA_String_MaxLen, 300, End,
  53.  
  54.                     Child, Label2("Name:"),
  55.                     Child, str1 = StringObject, StringFrame,
  56.                         MUIA_ExportID, 1,
  57.                         MUIA_UserData, "First and last name of user.",
  58.                         End,
  59.                     Child, Label2("Address:"),
  60.                     Child, str2 = StringObject, StringFrame,
  61.                         MUIA_ExportID, 2,
  62.                         MUIA_UserData, "Street, city and ZIP code." ,
  63.                         End,
  64.                     Child, Label1("Password:"),
  65.                     Child, str3 = StringObject, StringFrame,
  66.                         MUIA_ExportID, 4,
  67.                         MUIA_UserData, "Global access password (invisible).",
  68.                         MUIA_String_Secret, TRUE,
  69.                         End,
  70.                     Child, Label1("Sex:"),
  71.                     Child, cy1  = CycleObject,
  72.                         MUIA_ExportID, 6,
  73.                         MUIA_Cycle_Entries, sex,
  74.                         MUIA_UserData, "Guess what this means...",
  75.                         End,
  76.                     Child, Label("Age:"),
  77.                     Child, sl1  = SliderObject,
  78.                         MUIA_ExportID, 5,
  79.                         MUIA_Slider_Min, 9,
  80.                         MUIA_Slider_Max, 99,
  81.                         MUIA_UserData, "Several areas require a minimum age.",
  82.                         End,
  83.                     Child, Label1("Info:"),
  84.                     Child, help = TextObject, TextFrame,
  85.                         MUIA_UserData, "This is the info gadget.",
  86.                         End,
  87.                     End,
  88.  
  89.                 Child, VSpace(2),
  90.  
  91.                 Child, HGroup, MUIA_Group_SameSize, TRUE,
  92.                     Child, btsave   = SimpleButton("_Save"),
  93.                     Child, HSpace(0),
  94.                     Child, btuse    = SimpleButton("_Use"),
  95.                     Child, HSpace(0),
  96.                     Child, btcancel = SimpleButton("_Cancel"),
  97.                     End,
  98.  
  99.                 End,
  100.             End,
  101.         End;
  102.  
  103.     if (!app)
  104.         fail(app,"Failed to create Application.");
  105.  
  106.  
  107. /*
  108. ** Set Mouse Move Help Strings
  109. */
  110.  
  111.     DoMethod(window,MUIM_Notify,MUIA_Window_MouseObject,MUIV_EveryTime,
  112.         help,3,MUIM_CallHook,&HelpHook,MUIV_TriggerValue);
  113.  
  114.  
  115. /*
  116. ** Install notification events...
  117. */
  118.  
  119.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  120.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  121.  
  122.     DoMethod(btcancel,MUIM_Notify,MUIA_Pressed,FALSE,
  123.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  124.  
  125.     DoMethod(btsave,MUIM_Notify,MUIA_Pressed,FALSE,
  126.         app,2,MUIM_Application_ReturnID,ID_SAVE);
  127.  
  128.     DoMethod(btuse,MUIM_Notify,MUIA_Pressed,FALSE,
  129.         app,2,MUIM_Application_ReturnID,ID_USE);
  130.  
  131.  
  132. /*
  133. ** Cycle chain for keyboard control
  134. */
  135.  
  136.     DoMethod(window,MUIM_Window_SetCycleChain,
  137.         str1,str2,str3,cy1,sl1,btsave,btuse,btcancel,NULL);
  138.  
  139.  
  140. /*
  141. ** Concatenate strings, <return> will activate the next one
  142. */
  143.  
  144.     DoMethod(str1,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  145.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str2);
  146.  
  147.     DoMethod(str2,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  148.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str3);
  149.  
  150.     DoMethod(str3,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  151.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str1);
  152.  
  153.  
  154. /*
  155. ** The application is set up, now load
  156. ** a previously saved configuration from env:
  157. */
  158.  
  159.     DoMethod(app,MUIM_Application_Load,MUIV_Application_Load_ENV);
  160.  
  161.  
  162.  
  163. /*
  164. ** Input loop...
  165. */
  166.  
  167.     set(window,MUIA_Window_Open,TRUE);
  168.     set(window,MUIA_Window_ActiveObject,str1);
  169.  
  170.     while (running)
  171.     {
  172.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  173.         {
  174.             case MUIV_Application_ReturnID_Quit:
  175.             case ID_CANCEL:
  176.                 running = FALSE;
  177.                 break;
  178.  
  179.             case ID_SAVE:
  180.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENVARC);
  181.                 /* fall through */
  182.  
  183.             case ID_USE:
  184.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENV);
  185.                 running = FALSE;
  186.                 break;
  187.         }
  188.  
  189.         if (running && signals) Wait(signals);
  190.     }
  191.  
  192.     set(window,MUIA_Window_Open,FALSE);
  193.  
  194.  
  195. /*
  196. ** Shut down...
  197. */
  198.  
  199.     fail(app,NULL);
  200. }
  201.